//
//  QCSettingViewController.swift
//  爱汽车
//
//  Created by liujianlong on 2023/8/8.
//

import UIKit
import TCCKit

class QCSettingViewController: QCViewController {
    @IBOutlet var logoImg: UIImageView!
    var array = ["连接设备","系统设置","系统自检","关于"]
    override func viewDidLoad() {
        super.viewDidLoad()
        initUI()
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        QCTool.requestAboard()
        APP.checkOTA(false)
    }
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        initData()
    }
    override func initUI() {
        tableView.delegate = self
        tableView.dataSource = self
        tableView.register(QCSettingCell.nib(), forCellReuseIdentifier: QCSettingCell.ID())
        tableView.snp.makeConstraints { make in
            make.left.right.bottom.equalToSuperview()
            make.top.equalTo(logoImg.snp.bottom).offset(60)
        }
    }
}

//MARK: - UITableViewDataSource
extension QCSettingViewController : UITableViewDataSource
{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return array.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: QCSettingCell.ID()) as! QCSettingCell
        cell.img.image = UIImage(named: array[indexPath.row])
        cell.title.text = LS(array[indexPath.row])
        return cell
    }
}
//MARK: - UITableViewDelegate
extension QCSettingViewController : UITableViewDelegate
{
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        switch array[indexPath.row]{
        case "连接设备":
            push(QCSearchController(),true)
        case "系统设置":
            push(QCSystemSettingController(), true)
        case "系统自检":
            if isPressureMode {
                let vc = QCAlertPopViewController(useXib: true)
                vc.show("是否进行自动检测","否","是")
                vc.rightBtnBlock = {
                    CCHud.start(LS("请稍后..."),stopTime: 5)
                    BLEData.appSetDataToPer(AIQC.systemCheckStart.cmd, "00").write
                }
            }else{
                push(QCSystemCheckController(), true)
            }
        case "关于": 
            BLEData.checkFirmwareInfo.write
            CCHud.start("", stopTime: 1, handle: {[weak self] in
                self?.push(QCAboutViewController(), true)
            })
        default:
            break
        }
    }
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 0
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        return nil
    }
    
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        return nil
    }
}

